{extend name="../../admin/view/main"}
{block name='content'}
<form class="layui-form layui-card" action="{:request()->url()}" data-auto="true" method="post" autocomplete="off">
    <div class="layui-card-body padding-left-40">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>设备设置</legend>
        </fieldset>
        {if session('user.id')==10000 OR empty(str2arr(session('user.stores')))}
        <div class="layui-form-item layui-row layui-col-space15">
            <div class="layui-col-xs6 block relative">
                <span class="color-green label-required-prev">设备柜点</span><span class="margin-left-5 color-desc">Device Type</span>
                <select class="layui-select" required lay-search name="store_id">
                    <option selected value="">请选择 设备柜点</option>
                    {foreach $stores as $row}
                    {if isset($vo.store_id) AND $vo.store_id eq $row['id']}
                    <option selected value="{$row['id']}">{$row['name']}</option>
                    {else}
                    <option value="{$row['id']}">{$row['name']}</option>
                    {/if}
                    {/foreach}
                </select>
            </div>
            <label class="layui-col-xs6 block relative">
                <span class="color-green label-required-prev">设备编号</span><span class="margin-left-5 color-desc">Device Number</span>
                <input class="layui-input" name="device_no" required value="{$vo.device_no|default=''}" placeholder="请输入设备编号">
            </label>
        </div>

        <div class="layui-form-item layui-row layui-col-space15">
            <label class="layui-col-xs6 block relative">
                <span class="color-green label-required-prev">主板编号</span><span class="margin-left-5 color-desc">Board Number</span>
                <input class="layui-input" name="device_id" value="{$vo.device_id|default=''}" placeholder="请输入主板编号">
            </label>
            <label class="layui-col-xs6 block relative">
                <span class="color-green label-required-prev">箱格数量</span><span class="margin-left-5 color-desc">Box Count</span>
                <input class="layui-input" name="box_count" required value="{$vo.box_count|default=''}" placeholder="请输入设备箱格数量">
            </label>
        </div>
        {/if}

        {if auth("edit")}
        <div class="layui-form-item layui-row layui-col-space15">
            <label class="layui-col-xs6 block relative">
                <span class="color-green label-required-prev">联系人姓名</span><span class="margin-left-5 color-desc">Contact Name</span>
                <input class="layui-input" name="contacts" required value="{$vo.contacts|default=''}" placeholder="请输入联系人姓名">
            </label>
            <label class="layui-col-xs6 block relative">
                <span class="color-green label-required-prev">联系人电话</span><span class="margin-left-5 color-desc">Contact Number</span>
                <input class="layui-input" name="contact_number" lay-verify="required" required value="{$vo.contact_number|default=''}" placeholder="请输入联系人电话">
            </label>
        </div>
        {/if}

        <input type="hidden" name="half_type" value="2">
        <input type="hidden" name="device_type" value="1">

        {if session('user.id')==10000 OR empty(str2arr(session('user.stores')))}
        <div class="layui-form-item layui-row layui-col-space15">
            <label class="layui-col-xs6 block relative">
                <span class="color-green">主板流量卡卡号</span><span class="margin-left-5 color-desc">Board Phone Card</span>
                <input class="layui-input" lay-verify="card"  name="phone_card" required value="{$vo.phone_card|default=''}" placeholder="请输入主板流量卡卡号">
            </label>
            <label class="layui-col-xs6 block relative">
                <span class="color-green">平板流量卡卡号</span><span class="margin-left-5 color-desc">IPad Phone Card</span>
                <input class="layui-input" lay-verify="card" name="app_phone_card" required value="{$vo.app_phone_card|default=''}" placeholder="请输入平板流量卡卡号">
            </label>
        </div>

        <div class="layui-form-item layui-row layui-col-space15">
<!--            <div class="layui-col-xs6 block relative">-->
<!--                <span class="color-green label-required-prev">设备类型</span><span class="margin-left-5 color-desc">Device Type</span>-->
<!--                <select class="layui-select" lay-search name="device_type">-->
<!--                    <option selected value="">请选择 设备类型</option>-->
<!--                    {foreach $device_types as $key=>$type}-->
<!--                    {if isset($vo.device_type) AND $vo.device_type eq $key}-->
<!--                    <option selected value="{$key}">{$type}</option>-->
<!--                    {else}-->
<!--                    <option value="{$key}">{$type}</option>-->
<!--                    {/if}-->
<!--                    {/foreach}-->
<!--                </select>-->
<!--            </div>-->

            <input type="hidden" name="fee_id" value="{$vo.fee_id|default=0}">

            <label class="layui-col-xs3 block relative">
                <span class="color-green label-required-prev">设备状态</span><span class="margin-left-5 color-desc">Device Status</span><br>
                <div class="layui-input-inline">
                    {assign  name="status" value="$vo.status|default=1"}
                    <input type="radio" name="status" value="1" title="正常" {if $status==1}checked{/if}>
                    <input type="radio" name="status" value="0" title="停用" {if $status!=1}checked{/if}>
                </div>
            </label>

            <label class="layui-col-xs3 block relative">
                <span class="color-green label-required-prev">箱格是否可选</span><span class="margin-left-5 color-desc">Select Box</span><br>
                <div class="layui-input-inline">
                    {assign name="is_optional" value="$vo.is_optional|default=2"}
                    <input type="radio" name="is_optional" value="1" title="是" {if $is_optional==1}checked{/if}>
                    <input type="radio" name="is_optional" value="2" title="否" {if $is_optional==2}checked{/if}>
                </div>
            </label>


            <label class="layui-col-xs3 block relative">
                <span class="color-green label-required-prev">中途取物</span><span class="margin-left-5 color-desc">Pick up on the way</span><br>
                <div class="layui-input-inline">
                    {assign name="half_type" value="$vo.half_type|default=1"}
                    <input type="radio" name="half_type" value="1" title="允许" {if $half_type==1}checked{/if}>
                    <input type="radio" name="half_type" value="0" title="不允许" {if $half_type!=1}checked{/if}>
                </div>
            </label>
            <label class="layui-col-xs3 block relative">
                <span class="color-green">中途取物时长</span><span class="margin-left-10 color-red">PS：允许中途取物有效</span><br>
                <select class="layui-select" required lay-search name="half_hour">
                    {php}$fee_type = isset($vo['fee_type'])?$vo['fee_type']:0; $a = $fee_type==3?0:0.1; $half_hour = $vo['half_hour']??1.0; {/php}
                    {for start="$a" end="30.1" name="i" step="0.1"}
                    {php}$title = $fee_type==3 && $i<0.1?'不限时长':$i.'小时';{/php}
                    {if round($half_hour,1) eq round($i,1)}
                    <option selected value="{$i}">{$title}</option>
                    {else}
                    <option value="{$i}">{$title}</option>
                    {/if}
                    {/for}
                </select>
            </label>
        </div>
        {/if}

        {if auth("edit")}
        <div class="layui-form-item layui-row layui-col-space15">
<!--            <label class="layui-col-xs6 block relative">-->
<!--                <span class="color-green font-w7 label-required-prev">设备图片</span>-->
<!--                <span class="color-desc margin-left-5">Conver Image</span>-->
<!--                <label class="relative block label-required-null">-->
<!--                    <input required name="image" value='{$vo.image|default=""}' placeholder="请上传设备图片&nbsp;&nbsp;&nbsp;&nbsp;" class="layui-input">-->
<!--                    <a data-file data-type="png,jpg,gif" data-field="image" class="input-right-icon layui-icon layui-icon-upload"></a>-->
<!--                    <script>$('[name="image"]').uploadOneImage()</script>-->
<!--                </label>-->
<!--            </label>-->
<!--            <label class="layui-col-xs6 block relative">-->
<!--                <span class="color-green font-w7 ">设备二维码</span>-->
<!--                <span class="color-desc margin-left-5">Devices QrCode</span>-->
<!--                <label class="relative block label-required-null">-->
<!--                    <input name="qrcode" value='{$vo.qrcode|default=""}' placeholder="请上传设备二维码&nbsp;&nbsp;&nbsp;&nbsp;" class="layui-input">-->
<!--                    <a data-file data-type="png,jpg,gif" data-field="qrcode" class="input-right-icon layui-icon layui-icon-upload"></a>-->
<!--                    <script>$('[name="qrcode"]').uploadOneImage()</script>-->
<!--                </label>-->
<!--            </label>-->
        </div>

        <div class="layui-form-item layui-row layui-col-space15">
            <label class="layui-col-xs6 block relative">
                <span class="color-green font-w7 ">设备二维码</span>
                <span class="color-desc margin-left-5">Devices QrCode</span>
                <label class="relative block label-required-null">
                    <input name="qrcode" value='{$vo.qrcode|default=""}' placeholder="请上传设备二维码&nbsp;&nbsp;&nbsp;&nbsp;" class="layui-input">
                    <a data-file data-type="png,jpg,gif" data-field="qrcode" class="input-right-icon layui-icon layui-icon-upload"></a>
                    <script>$('[name="qrcode"]').uploadOneImage()</script>
                </label>
            </label>

            <label class="layui-col-xs6 block relative">
                <span class="color-green">备注信息</span><span class="margin-left-5 color-desc">Start Hours</span>
                <textarea class="layui-textarea" name="remark" cols="3" placeholder="请输入备注信息">{$vo.remark|default=''}</textarea>
            </label>
        </div>
        {/if}
    </div>
    <div class="hr-line-dashed"></div>
    {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}

    <div class="layui-form-item text-center" style="padding-bottom: 20px;">
        {if $title!="查看设备"}
        <button class="layui-btn" lay-submit lay-filter="submit">保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-history-back>取消编辑</button>
        {/if}
    </div>

</div>

</form>
{/block}

{block name='script'}
<script src="/static/plugs/city-picker/city-picker.data.js"></script>
<script>
    (function () {
        var title = "{$title}";
        if(title=='查看设备'){
            $("input,select").attr("readOnly", true);
        }

        layui.form.on('select(fees)',function (data){
            let fee_type = data.elem[data.elem.selectedIndex].dataset.fee_type
            if(fee_type!=undefined){
                $("#fee_type").val(fee_type);
            }
        });

        layui.form.on('radio', function(data){
            $(this).val(data.value);
        });

        layui.form.verify({
            card: [
                /^[\S]{20}$/
                ,'位数不够，请输入正确的20位卡号'
            ]
        });

        layui.form.render();

        window.form.on('radio', radios);

        function radios(data) {
            key = $(this).attr('name');
            $("input[name="+key+"]").val(data.value);
        }

    })();
</script>
{/block}